package com.example.admin.SQLite.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.example.admin.SQLite.Complaint;
import com.example.admin.SQLite.SqLiteOpenHelper;
import com.example.admin.SQLite.feiyong;

import java.util.ArrayList;

import static com.example.admin.SQLite.SqLiteOpenHelper.FEIYONG;

public class feiyongDao {
    SqLiteOpenHelper dbHelper;
    private static final String KEY_ID = "id";

    public feiyongDao(Context context) {
        dbHelper = new SqLiteOpenHelper(context);
    }
    public long addData(feiyong bean) {
        SQLiteDatabase db = dbHelper.getSqlite();
        ContentValues values = new ContentValues();
        values.put("feiyongAmount", bean.feiyongAmount);
        values.put("feiyongStatu", bean.feiyongStatu);
        values.put("feiyongShequ", bean.feiyongShequ);
        values.put("feiyongType", bean.feiyongType);
        values.put("feiyongHome", bean.feiyongHome);
        long id = db.insert(FEIYONG, null, values);
        Log.e("的收费收费的方式", "addData: " + id);
        return id;
    }
    public ArrayList<feiyong> FindWhereData() {

        SQLiteDatabase db = dbHelper.getSqlite();
        Cursor cursor = db.rawQuery("SELECT * FROM " + FEIYONG, null);
        ArrayList<feiyong> arrContacts = new ArrayList<>();
        while (cursor.moveToNext()) {
            feiyong model = new feiyong();
            model.id = cursor.getInt(0);
            model.feiyongAmount = cursor.getString(1);
            model.feiyongStatu = cursor.getString(2);
            model.feiyongShequ = cursor.getString(3);
            model.feiyongType = cursor.getString(4);
            model.feiyongHome = cursor.getString(5);

            arrContacts.add(model);

        }
        return arrContacts;
    }

    public void updateCom(int id, String str) {

        SQLiteDatabase database  = dbHelper.getSqlite();

        ContentValues cv = new ContentValues();
        cv.put("feiyongStatu", str);

        database.update(FEIYONG, cv, KEY_ID + " = " + id, null);
    }

}
